package edu.hm.swe2.shareit.dao;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import edu.hm.swe2.shareit.domain.Adresse;


public class AdresseDAO
{

	
	private EntityManager emgr = Persistence
			.createEntityManagerFactory("ShareItJPA").createEntityManager();

	public final void create(Adresse adr)
	{
		emgr.getTransaction().begin();
		emgr.persist(adr);
		emgr.getTransaction().commit();
	}

	public Adresse read(int id) {
		return emgr.find(Adresse.class, id);
	}

	public final void update(Adresse adr)
	{
		emgr.getTransaction().begin();
		emgr.merge(adr);
		emgr.getTransaction().commit();
	}

	public final void delete(Adresse adr)
	{
		emgr.getTransaction().begin();
		adr = emgr.merge(adr);
		emgr.remove(adr);
		emgr.getTransaction().commit();
	}
}
